package com.xb.cloud.gateway.client;

/**
 * 
 * @ClassName: ResultCodes
 * @Description:项目统一返回状态码
 * @author: 鲜备科技
 * @date: 2017年12月25日 上午10:45:21
 * 
 * @Copyright: 2017 www.xianbeitech.com Inc. All rights reserved.
 *
 */
public enum ReturnCodes {

	// API模块名-前四位对应接口，中间2位错误类型（第一位，2.前端入参错误 3.service内部错误 4.调用第三方出错
	// 5.业务异常(业务逻辑)），后2位自定义
	SUCCESS("00000000", "success", "成功"), //
	SYSTEM_EXCEPTION("99999999", "system exception", "系统异常"),

	// 用户操作错误码：1******
	PARAM_INVALID("usercenter-10模块 01方法 21错误类型  01自定义类型 ", "login param invalid", "参数错误"), //

	PHONENUM_REQUIRED("usercenter-10012101", "phoneNum is required", "手机号码不能为空"), //
	PHONENUM_INVALID("usercenter-10012102", "phoneNum is invalid", "手机号码格式错误"), //
	PASSWORD_REQUIRED("usercenter-10012103", "password is required", "密码不能为空"), //
	PASSWORD_INVALID("usercenter-10012104", "password is invalid", "密码格式错误"), //

	USER_NOT_EXIST("usercenter-10015105", "user not exist", "登录用户不存在"), //
	USER_NOT_INITIALIZE("usercenter-10015106", "user not initialize", "用户还未初始化，用户需初始化密码"), //
	PASSWORD_DECRYPT_ERROR("usercenter-10015107", "password invalid, decrypt error", "密码解析错误"), //
	PASSWORD_ERROR("usercenter-10015108", "password is error", "用户密码错误"), //
	PHONENUM_OR_PASSWORD_ERROR("usercenter-10015109", "phonenum or password error", "手机号或密码错误"), //

	VERIFYCODE_REQUIRED("usercenter-10022101", "verifycode is required", "短信验证码不能为空"), //
	VERIFYCODE_INVALID("usercenter-10022102", "verify code is invalid", "短信验证码格式错误"), //
	VERIFYCODE_ERROR("usercenter-10025102", "verifycode is error", "短信验证码错误"), //
	USER_CREATE_ERROR("usercenter-10024101", "user create error", "短信验证码错误"), //

	VERIFYCODE_SEND_LIMIT_REACHED("usercenter-10035101", "verifycode send limit reached", "短信验证码每天发送5次达到限制"), //
	VERIFYCODE_SEND_FREQUENTLY("usercenter-10035102", "verifycode send frequently", "短信验证码发送频繁"), //
	VERIFYCODE_SEND_FAILED("usercenter-10034103", "verify code send failed", "短信验证发送失败"), //

	AUTO_USER_TOKEN_REQUIRED("usercenter-10045101", "auto user token is required", "autoUserToken不能为空"), //
	AUTO_USER_TOKEN_INVALID("usercenter-10045102", "auto user token invalid", "autoUserToken过期，请重新登录"), //

	PASSWORD_RESET_FAILED("usercenter-10055101", "reset password failed", "重置密码失败"), //
	REGISTER_USER_NO_EXIST("usercenter-11062101", "user no exist", "用户不存在"), // yyh
	REGISTER_USER_EXIST("usercenter-11062101", "user already exist", "用户已存在"), //
	REGISTER_VERIFYCODE_ERROR("usercenter-10062102", "user register verifycode is error", "短信验证码错误"), //

	PRODUCT_SKU_IS_FOLLOWED("usercenter-10062103", "current sku is favorite already", "当前sku已经被收藏"), //
	PRODUCT_SKU_IS_NOT_FOLLOWED("usercenter-10062104", "current sku is not favorite", "当前sku未被收藏"),

	/***** 用户订单管理 *****/
	// 订单列表查询
	PAGE_NUM_INVALID("usercenter-11012100", "page num is invalid", "当前页数不正确"), //
	// 订单详情查询
	ORDER_NOT_EXIST("usercenter-11022101", "order not exist", "查询订单不存在"), //
	// 短信通知商家支付成功发送失败
	NOTIFY_MERCHANT_SEND_FAILED("usercenter-11045101", "notify merchant payed msg send failed", "通知商家信息发送失败"), //

	// 购物流程错误码：2******
	// 20-购物流程，01购物车
	SKU_NOT_EXIST("shopping-20012101", "sku not exist", "商品不存在"), //
	SKU_CANNOT_SALE("shopping-20015101", "sku cannot sale", "商品不能销售，已被删除或下架"), //
	SKU_STOCK_NOT_ENOUGH("shopping-20015102", "sku stock not enough", "商品库存不足"), //

	// 20-购物流程，02下单
	COMPANY_INVALID("shopping-20025201", "company invalid", "公司不合法"), //
	ENDUSER_INVALID("shopping-20025202", "enduser invalid", "终端用户不合法"), //
	MERCHANT_MULTIPLE("shopping-20025203", "merchant multiple", "请选择同一个商家的商品进行下单"), //
	MERCHANT_INVALID("shopping-20025204", "merchant invalid", "商家不合法"), //
	SHOP_MULTIPLE("shopping-20025205", "shop multiple", "请选择同一个店铺的商品进行下单"), //
	SHOP_INVALID("shopping-20025206", "shop invalid", "店铺不合法"), //
	CHECKOUT_EMPTY_SKU("shopping-20022101", "checkout empty sku list", "请选择需要结算的商品"), //
	SHOPPINGCART_CHANGED("shopping-20025101", "shoppingcart info changed", "购物车已被修改，请刷新重试"), //
	NEED_ORDER_ADDRESS("shopping-20022102", "need order address", "请选择收货地址"), //
	ORDER_ADDRESS_INVALID("shopping-20022103", "order address invalid", "请选择有效的收货地址"), //
	OEDER_CANCEL_ERROR("shopping-20022301", "order cancel error", "订单取消失败"), //
	OEDER_CANCEL_FAILED("shopping-20032401", "order cancel failed", "订单取消失败"), //
	OEDER_DELETE_ERROR("shopping-20032501", "order delete error", "订单删除失败"), //

	// 20-购物流程，04支付
	PAYMENT_REQUEST_ERROR("shopping-20044001 ", "payment request error", "支付下单请求失败"), //
	PAYMENT_RETURN_VERIFY_ERROR("shopping-20044002", "payment return verify error", "支付下单请求返回验证失败"), //
	PAYMENT_RETURN_EMPTY_DATA("shopping-20044003", "payment return empty data error", "支付下单请求返回数据为空"), //
	PAYMENT_FLOW_CREATE_ERROR("shopping-20043003", "payment flow create error", "新建下单流水出错"), //

	// 前端商品展示等错误码：3******
	CATGEORY_NUM_INVALID("product-3001010", "catgeory num is empty", "类目参数非法"), //
	SKU_NUM_INVALID("product-3001011", "sku id is empty", "SKU参数非法"), //
	// 商家端 4******
	MERCHANT_NOT_EXIST("merchantcenter-40015101", "merchant not exist", "合法的商家用户不存在"), //
	MERCHANT_CREATE_ORDER_ERROR("merchantcenter-40014100", "merchant create order error", "商家代客下单失败"), //

	// 商品发布模块:41
	PRODUCT_MONGO_NOT_EXIST("productpublish-41015101", "product mongo not exist", "产品的缓存不存在"), //
	PRODUCT_MONGO_SAVE_FAILED("productpublish-41025101", "product mongo save failed", "产品的缓存保存失败"), //
	PRODUCT_SERIES_MONGO_SAVE_FAILED("productpublish-41035101", "product series mongo save failed", "系列产品的系列组合缓存保存失败"), //
	PRODUCT_SERIES_MONGO_NOT_EXIST("productpublish-41045101", "product series mongo not exist", "系列产品的系列组合缓存不存在"), //

	PRODUCT_TEMPLATE_NOT_EXIST("productpublish-42025101", "product template not exist", "产品的模板不存在"), //

	// 文件上传
	UPLOAD_TYPE_ERROR("upload-49025101", "form type error!", "表单必须包含 enctype=multipart/form-data"),

	// 支付 5******
	SHOP_NOT_EXIST("payment-50015101", "shop not exist", "合法的店铺不存在"), //
	PAYMENTCODE_NOT_EXIST("payment-50015201", "Paymentcode not exist", "店铺收款不存在"), //

	// 搜索 6******
	SEARCH_KEY_ILLEGAL("search-60025101", "search keyword is illegal ", "搜索关键字非法"), //
	// 报表7*****
	STATEMENT_QUERY_DATE_ILLEGAL("statement-70025101", "query date  is illegal ", "查询时间非法"), //
	;

	private final String code;
	private final String msg;
	private final String detail;

	private ReturnCodes(String code, String msg, String detail) {
		this.code = code;
		this.msg = msg;
		this.detail = detail;
	}

	public String getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public String getDetail() {
		return detail;
	}

	public static ReturnCodes getEnumByCode(String code) {
		for (ReturnCodes p : ReturnCodes.values()) {
			if (p.getCode().equalsIgnoreCase(code)) {
				return p;
			}
		}
		return null;
	}
}
